package com.gitee.wsl.struct.tree.ext

import com.gitee.wsl.struct.tree.MutableNodeElement

fun <T> MutableNodeElement<T>.swap(node: MutableNodeElement<T>){
    if(this == node) return
    val currentParent = this.parent
    val otherParent = node.parent
    this.removeSelf()
    node.removeSelf()
    currentParent?.add(node)
    otherParent?.add(this)
    this.parent = otherParent
    node.parent = currentParent
}

fun <T> MutableNodeElement<T>.swapData(node: MutableNodeElement<T>){
    val thisData = data
    data = node.data
    node.data = thisData
}